﻿Imports System
Imports System.Workflow.ComponentModel
Imports System.Workflow.ComponentModel.Design

Namespace System.Workflow.ComponentModel.Compiler
    Public Class ActivityValidator
        Inherits DependencyObjectValidator
        ' Methods
        Public Overrides Function Validate(ByVal manager As ValidationManager, ByVal obj As Object) As ValidationErrorCollection
            If (manager Is Nothing) Then
                Throw New ArgumentNullException("manager")
            End If
            Dim context As Activity = [TryCast](obj,Activity)
            If (context Is Nothing) Then
                Throw New ArgumentException(SR.GetString("Error_UnexpectedArgumentType", New Object() { GetType(Activity).FullName }), "obj")
            End If
            If (manager.Context Is Nothing) Then
                Throw New ArgumentException("manager", SR.GetString("Error_MissingContextProperty"))
            End If
            manager.Context.Push(context)
            Dim errors As New ValidationErrorCollection
            errors.AddRange(MyBase.Validate(manager, obj))
            If (context.Parent Is Nothing) Then
                errors.AddRange(ValidationHelpers.ValidateUniqueIdentifiers(context))
                If Not context.Enabled Then
                    Dim item As New ValidationError(SR.GetString("Error_RootIsNotEnabled"), &H628) { _
                        .PropertyName = "Enabled" _
                    }
                    errors.Add(item)
                End If
            End If
            Dim rootActivity As Activity = Helpers.GetRootActivity(context)
            If (Not context Is rootActivity) Then
                Dim error2 As ValidationError = ValidationHelpers.ValidateNameProperty("Name", manager, context.Name)
                If (Not error2 Is Nothing) Then
                    errors.Add(error2)
                End If
            End If
            Try 
                errors.AddRange(Me.ValidateProperties(manager, obj))
            Finally
                manager.Context.Pop
            End Try
            Return errors
        End Function

    End Class
End Namespace

